package cn.agiledata.bank.common.notice.logic;

import java.util.Map;

import org.apache.log4j.Logger;

import cn.agiledata.sms.SmsService;

import cn.agiledata.bank.common.exception.BusinessException;
import cn.agiledata.bank.common.service.NotifyMail;
import cn.agiledata.bank.common.util.StringUtil;
import cn.agiledata.bank.facade.helper.TemplateHelper;

/**
 * 短信通知
 * 
 * @author 马贤波
 * 
 */
abstract class SmsNotice extends AbstractNotice {
	protected final static Logger log = Logger.getLogger(NotifyMail.class);

	// 手机
	private String mobileNo;

	private TemplateHelper template;

	private SmsService smsService;

	private String smsContext;

	// 手动set
	private Map vnvMap;

	protected final void setVnvMap(Map vnvMap) {
		this.vnvMap = vnvMap;
	}

	public void setReceiver(String receiver) {
		this.mobileNo = receiver;
	}

	public void setSmsContext(String smsContext) {
		this.smsContext = smsContext;
	}



	public SmsService getSmsService() {
		return smsService;
	}

	public void setSmsService(SmsService smsService) {
		this.smsService = smsService;
	}

	public void setTemplate(TemplateHelper template) {
		this.template = template;
	}

	/**
	 * 发送短信
	 * 
	 * @param mobile
	 *            手机号码
	 * @param vnvMap
	 *            参数变量
	 */
	public void send() {
		String text = StringUtil.appendWebSiteUrl(this.template.mergeContent(
				smsContext, this.vnvMap));
		try {
			this.smsService.sendMessage(this.mobileNo, text);
			log.debug("短信发送完成...");
		} catch (Exception e) {
			log.error(e);
		}
	}

}
